{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline \n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import ipywidgets as wg\n",
    "from ipywidgets import HBox, VBox\n",
    "from IPython.display import display"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Lin_Interpolation(size):\n",
    "    #  Точки интерполируемой функции:\n",
    "    xp = np.linspace(-np.pi, np.pi, 41)\n",
    "    fp = np.sinc(xp)\n",
    "\n",
    "    #  Вычисленные точки интерполяции:\n",
    "    x = np.linspace(-np.pi, np.pi, 71)\n",
    "    y = np.interp(x, xp, fp)\n",
    "\n",
    "\n",
    "    fig, ax = plt.subplots()\n",
    "\n",
    "    ax.axis(xmin=-size,xmax=size)\n",
    "    ax.axis(ymin=-size,ymax=size)\n",
    "\n",
    "    ax.plot(xp, fp,\n",
    "            marker = 'o',\n",
    "            label = 'sinc(x)')\n",
    "    ax.plot(x, y,\n",
    "            marker = 'x',\n",
    "            label = 'interp')\n",
    "\n",
    "    ax.set_title('Линейная интерполяция точек')\n",
    "\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b21790a6f28546b988514700980e514a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=1.0, description='Size:', max=10.0, min=1.0), Output()), _dom_classes=…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.Lin_Interpolation(size)>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "size_slide = wg.FloatSlider(value=1.0,min=1,max=10.0,step=0.1,description='Size:')\n",
    "interpolation_slide = wg.FloatSlider(value=71,min=1,max=100,step=1,description='Interpolation step:')\n",
    "wg.interact(Lin_Interpolation, size=size_slide)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(1, 1), (2, 2), (3, 3), (4, 4), (5, 3), (6, 2), (7, 2)]\n"
     ]
    }
   ],
   "source": [
    "array = [\n",
    "    (1, 1),\n",
    "    (2, 2),\n",
    "    (3, 3),\n",
    "    (4, 4),\n",
    "    (5, 3),\n",
    "    (6, 2),\n",
    "    (7, 2),\n",
    "]\n",
    "print(array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Lin_Interpolation_3(size, arr, theta):\n",
    "       \n",
    "    arr1 = arr\n",
    "    arr1 = [list(map(lambda x: x*size, z)) for z in array]\n",
    "    x_os = []\n",
    "    y_os = []\n",
    "\n",
    "    n=len(arr1)\n",
    "    for i in range(n):\n",
    "        x_os.append(arr1[i][0]) \n",
    "    for i in range(n):\n",
    "        y_os.append(arr1[i][1])\n",
    "        \n",
    "    \n",
    "    xp = x_os\n",
    "    fp = y_os    \n",
    "    #----------------\n",
    "    thet = theta\n",
    "    P = np.array([xp,fp])\n",
    "#     print(\"P = \\n\", P)\n",
    "    thet = thet/180*np.pi\n",
    "#     print(\"Thet in radian = \", thet)\n",
    "    rot = np.array([[np.cos(thet), -np.sin(thet)],\n",
    "                    [np.sin(thet), np.cos(thet)]])\n",
    "#     print(\"Matrix rotation: \\n\",rot)\n",
    "    rot = np.linalg.inv(rot)\n",
    "#     print(\"Inverse matrix rotation: \\n\", rot)\n",
    "\n",
    "    P2 = rot.dot(P)\n",
    "#     print(\"P2 = \\n\", P2)\n",
    "    \n",
    "    xp.clear()\n",
    "    fp.clear()\n",
    "    \n",
    "    for i in range(n):\n",
    "        xp.append(P2[0][i]) \n",
    "        \n",
    "    for i in range(n):\n",
    "        fp.append(P2[1][i])\n",
    "        \n",
    "#     print(\"x' =\\n\",xp)\n",
    "#     print(\"y' =\\n\",fp)\n",
    "\n",
    "    x = x_os\n",
    "    fig, ax = plt.subplots()\n",
    "\n",
    "#     print(\"x' =\\n\",xp)\n",
    "#     print(\"y' =\\n\",fp)\n",
    "\n",
    "    ax.plot(xp, fp,\n",
    "            marker = 'o',\n",
    "            label = 'sinc(x)')\n",
    "\n",
    "    ax.set_title('График')\n",
    "\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5c5138b99125403bbf8f366479144e31",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=1.0, description='Size:', max=10.0, min=1.0), Dropdown(description='ar…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.Lin_Interpolation_3(size, arr, theta)>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "size_slide = wg.FloatSlider(value=1.0,min=1,max=10.0,step=0.1,description='Size:')\n",
    "interpolation_slide = wg.FloatSlider(value=71,min=1,max=100,step=1,description='Interp step:')\n",
    "thet_slide = wg.FloatSlider(value=0,min=-360,max=360,step=1,description='Thet:')\n",
    "wg.interact(Lin_Interpolation_3, size=size_slide ,arr=array, theta=thet_slide)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
